package io.github.fb513.api.util;

import io.github.fb513.api.enums.RespMetaEnum;
import io.github.fb513.api.exception.WebBaseException;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class FutureUtils {

    public static void waitAllTasks(CompletableFuture<?>... tasks) {
        try {
            CompletableFuture.allOf(tasks).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new WebBaseException(RespMetaEnum.TIMEOUT, e);
        }
    }

    public static void waitAllTasks(List<CompletableFuture<?>> futureList) {
        waitAllTasks(futureList.toArray(new CompletableFuture[0]));
    }
}
